const { src, dest, parallel, series } = require('gulp');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const gulpMinifyCss = require('gulp-minify-css')
const gulpRm = require('gulp-rm');

// 打包之前先清空
function clean(){
  return src('./output/**/*')
  .pipe(gulpRm())
}

// 处理css
function dealCss(){
  return src('./src/css/*.css')
  // .pipe(dest('./output/css/'))
  .pipe(gulpMinifyCss())
  .pipe(rename({extname: '.min.css'}))
  .pipe(dest('./output/css'))
}
// 处理js
function dealJs() {
  return src('src/*.js')
    .pipe(babel())
    .pipe(src('vendor/*.js'))
    // .pipe(dest('output/'))
    .pipe(uglify())
    .pipe(rename({ extname: '.min.js' }))
    .pipe(dest('output/'));
}

exports.default = series(clean,parallel(dealCss, dealJs))
